Skip to content

Widen ValidationError :key type to allow lists#151

Merged
whatyouhide merged 1 commit into
dashbitco:mainfrom
cgarvis:fix/widen-validation-error-key-type
May 27, 2026
Merged

Widen ValidationError :key type to allow lists#151
whatyouhide merged 1 commit into
dashbitco:mainfrom
cgarvis:fix/widen-validation-error-key-type

Conversation

@cgarvis

@cgarvis cgarvis commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

%NimbleOptions.ValidationError{}.key is typed atom() but the struct already stores a list of atoms for the "unknown options" case. This PR widens the type to match runtime behavior.

Evidence

  • The "unknown options" error path passes a list of keys at lib/nimble_options.ex:524:

    keys ->
      error_tuple(
        keys,
        nil,
        "unknown options #{inspect(keys)}, valid options are: #{inspect(valid_opts)}"
      )
  • test "unknown options" asserts the list form:

    key: [:not_an_option1, :not_an_option2]
  • Runtime behavior is intentional. The typespec was misleading.

Why this matters

The set-theoretic type checker introduced in elixir-lang/elixir#15366 reads @type t :: %__MODULE__{key: atom()} literally. Every call site that passes a list where atom() is declared fires a warning. nimble_options is depended on by several top Hex packages (finch, oban, req, swoosh, tesla, ex_aws, phoenix_live_view), so this single mismatch cascades into downstream warnings for their consumers.

Widening the type matches what the code already does. No code change, no test change.

Change

-          key: atom(),
+          key: atom() | [atom()],

Plus a doc update on the :key field calling out the multi-key case.

Verification

mix test: 156/156 pass. mix compile clean under the new checker.

The struct already stores a list of atoms for the "unknown options"
error (lib/nimble_options.ex:524 passes a list of keys; test
"unknown options" asserts `key: [:not_an_option1, :not_an_option2]`).
The @type for the field said `atom()` only, so the new set-theoretic
checker in elixir-lang/elixir#15366 flags every caller of error_tuple
at that site and cascades into every package that depends on
nimble_options.

Widening to `atom() | [atom()]` matches actual runtime behavior. Doc
updated to call out the multi-key case. No code change, no test
change.

Signed-off-by: Chris Garvis <cgarvis@gmail.com>
@cgarvis cgarvis force-pushed the fix/widen-validation-error-key-type branch from 33d6226 to c6fba6b Compare May 13, 2026 03:01
@whatyouhide whatyouhide merged commit b2d36ba into dashbitco:main May 27, 2026
2 checks passed
@whatyouhide

Copy link
Copy Markdown
Collaborator

Thanks @cgarvis! 💟

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 0

Coverage remained the same at 93.793%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 290
Covered Lines: 272
Line Coverage: 93.79%
Coverage Strength: 190.57 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants